/**
 * 
 */
package org.gigi.security;

import java.util.ArrayList;
import java.util.List;

import org.gigi.security.domain.Authority;
import org.gigi.security.domain.Group;
import org.gigi.security.domain.GroupUser;
import org.gigi.security.domain.GroupUserPk;
import org.gigi.security.domain.Menu;
import org.gigi.security.domain.User;

/**
 * 生成测试用对象的工厂类
 *
 * @author Eugene Wang 2011-5-28
 * @see
 */
public class SecurityTestObjectFactory {
	/**
	 * 生成测试用的用户对象
	 * @return
	 */
	public static User createUser() {
		User user = new User();
		user.setUsername("test");
		user.setPassword("test");
		user.setAccountNonExpired(Boolean.TRUE);
		user.setAccountNonLocked(Boolean.TRUE);
		user.setCredentialsNonExpired(Boolean.TRUE);
		user.setEnabled(Boolean.TRUE);
		return user;
	}

	/**
	 * 生成测试用的用户列表
	 * @return
	 */
	public static List<User> createUserList() {
		List<User> users = new ArrayList<User>();
		User user = SecurityTestObjectFactory.createUser();
		user.setUsername("test2");
		users.add(user);
		user = SecurityTestObjectFactory.createUser();
		user.setUsername("test3");
		users.add(user);
		return users;
	}

	/**
	 * 生成测试用的GroupUser列表。
	 * @return
	 */
	public static List<GroupUser> createGroupUserList() {
		List<GroupUser> result = new ArrayList<GroupUser>();
		GroupUser groupUser = new GroupUser();
		groupUser.setId(new GroupUserPk(-1l, "test2"));
		result.add(groupUser);
		groupUser = new GroupUser();
		groupUser.setId(new GroupUserPk(-1l, "test3"));
		result.add(groupUser);
		return result;
	}
	/**
	 * 生成测试用的用户组对象
	 * @return
	 */
	public static Group createGroup() {
		Group group = new Group();
		group.setId(-1);
		group.setName("用户组1");
		group.setLayerOrder(1);
		return group;
	}

	/**
	 * 生成测试用的菜单对象。
	 * @return
	 */
	public static Menu createMenu() {
		Menu menu = new Menu();
		menu.setCode("M_FILE");
		menu.setName("文件");
		menu.setUrl("/file");
		menu.setLayerOrder(1);
		return menu;
	}

	/**
	 * 成成测试用的顶级菜单列表。
	 * @return
	 */
	public static List<Menu> createMenuList() {
		Menu file = createMenu();
		Menu newFile = new Menu();
		newFile.setCode("NEW");
		newFile.setName("新建");
		newFile.setUrl("/file/new");
		newFile.setLayerOrder(1);
		newFile.setParent(file);
		List<Menu> result = new ArrayList<Menu>();
		result.add(file);
		return result;
	}
	/**
	 * 生成测试用得权限列表。
	 * @return
	 */
	public static List<Authority> createAuthorityList() {
		List<Authority> result = new ArrayList<Authority>();
		for (int i = 1; i < 3; i++) {
			Authority authority = new Authority();
			authority.setCode("AUTH_TEST_"+i);
			result.add(authority);
		}
		return result;
	}
}
